# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
   
 #exterbalIcon is the one most people need.
 #
 def externalIcon(item)
    return "<a href=\"#{externalURL(item)}\">#{externalIconImg(item)}</a>"
 end
 
 
 def externalIconURL(item)
    #http://www.wowhead.com/images/icons/medium/INV_Belt_13.jpg
    
    if item.iconname    
      name = item.iconname + ".jpg"
    else
      name = "INV_Misc_QuestionMark.jpg"
    end
    return "http://www.wowhead.com/images/icons/medium/#{name}"    
  end
 
  def externalURL(item)
    return "http://www.wowhead.com/?item=#{item.wowlink}"
  end  
  
  def externalURLHref(item)
    #<a href="<%= externalURL(item)%>"><%= item.name %></a>
    name = externalURL(item)
    return "<a href=\"#{name}\">#{item.name}</a>"
  end
  
  def externalIconImg(item)
    #<img src="<%= externalIcon(item)%>"></img>
    url = externalIconURL item
    return "<img src=\"#{url}\"/>"
  end
  
  
  def timestamp(time)
    time.strftime("%H:%M")
  end
  
  def datestamp(time)
    time.strftime("%A #{time.day.ordinalize} %B")
  end
  
  def timediff(begintime, endtime)
    diff = endtime - begintime
    diff = (diff.to_f / 360).round
    diff.to_f / 10
  end
  
end
